<?php

namespace App\Admin\Extensions\Tools;

use Encore\Admin\Grid\Tools\BatchAction;

/**
 *禁封账号.
 */
class FreezeAction extends BatchAction
{
    public function script()
    {
        $tips = trans('game.select_role');
        return <<<EOT
        $('#exp_time').datetimepicker({
        "format": "YYYY-MM-DD HH:mm:ss",
        "locale": "zh-CN"
	    });

    	$('{$this->getElementClass()}').on('click', function() {
		    var playerIds = selectedRows();
	        if(playerIds == ''){
		        swal("{$tips}");return;
		    }
    		$("#freeze-modal").modal();
    	});

	   //提交表单
        $("#freeze-submit").on('click',function(){
		    var exp_time = $("input[name='exp_time']").val();
	        var param = {
	            type: 'post',
	            url: '{$this->resource}/banned',
	            data: {
	                _token: LA.token,
	                ids: selectedRows(),
	                exp_time: exp_time,
	            },
	            success: function(data) {
	                $.pjax.reload('#pjax-container');
	                $(".close").click();
	                toastr.success(data.message);
	            }
	        };
        ajaxHttp(param);
        });
EOT;
    }
}
